package com.rightsidetech.http.controller.admin.advert;

import com.github.pagehelper.PageInfo;
import com.rightsidetech.commom.base.DelReq;
import com.rightsidetech.commom.base.ResponseData;
import com.rightsidetech.commom.enums.ModifyName;
import com.rightsidetech.http.aspect.Auth;
import com.rightsidetech.http.aspect.Log;
import com.rightsidetech.http.aspect.ModifyLog;
import com.rightsidetech.http.aspect.Token;
import com.rightsidetech.http.base.BaseController;
import com.rightsidetech.system.dtos.request.adverts.AdvertsLoadSaveReq;
import com.rightsidetech.system.dtos.request.adverts.AdvertsLoadUpReq;
import com.rightsidetech.system.dtos.request.adverts.AdvertsPageReq;
import com.rightsidetech.system.dtos.response.adverts.AdvertsPageResp;
import com.rightsidetech.system.service.SysAdvertsLoadService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shenyu.client.springmvc.annotation.ShenyuSpringMvcClient;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/admin/advert/")
@ShenyuSpringMvcClient(path = "/admin/advert/**")
@Api(tags = "广告载入页相关")
public class AdvertsLoadController extends BaseController {

    @Resource
    private SysAdvertsLoadService sysAdvertsLoadService;

    @Token
    @Log
    @Auth(bizType = Auth.OPERATOR)
    @PostMapping("/save")
    @ApiOperation("添加广告载入页")
    @ModifyLog(serviceClass = SysAdvertsLoadService.class,modifyType = ModifyName.SAVE)
    public ResponseData saveLoad(@RequestBody AdvertsLoadSaveReq req) throws Exception {
        Long loginInfoId = Long.parseLong(getAttribute());
        String loginName = getLoginName();
        if(null == loginInfoId || null == loginName){
            return ResponseData.fail("未找到登录人");
        }
        return sysAdvertsLoadService.saveAdverts(req,loginName);
    }

    @Token
    @Log
    @Auth(bizType = Auth.OPERATOR)
    @GetMapping("/page")
    @ApiOperation("分页查询")
    public ResponseData<PageInfo<AdvertsPageResp>> page(AdvertsPageReq req){
        return sysAdvertsLoadService.page(req);
    }

    @Token
    @Log
    @Auth(bizType = Auth.OPERATOR)
    @PostMapping("/update")
    @ApiOperation("修改广告载入页")
    @ModifyLog(serviceClass = SysAdvertsLoadService.class)
    public ResponseData updateLoad(@RequestBody AdvertsLoadUpReq req){
        return sysAdvertsLoadService.update(req);
    }

    @Token
    @Log
    @Auth(bizType = Auth.OPERATOR)
    @PostMapping("/del")
    @ApiOperation("删除")
    @ModifyLog(serviceClass = SysAdvertsLoadService.class)
    public ResponseData delLoad(@RequestBody DelReq req){
        return sysAdvertsLoadService.del(req);
    }

}
